<include file="default/public/header_common" />

<style>
.am-list > li {
    position: relative;
    display: block;
    margin-bottom: -1px;
    background-color:initial;
    border: 1px solid #dedede;
    border-width: 1px 0;
	padding:15px;
}
.am-list > li > i {
	font-style:normal;
}
.head-css {
	background-color:#fff; 
	width:100%;
	height:auto;
	padding:20px 0;
}
.head-box {
	width:182px;
	height:182px;
	margin:0 auto;
}
.uploader-head{
	width:230px;
	height:230px;
	margin:0 auto;
}
.uploader-list {
    width: 100%;
    overflow: hidden;
}
#uploader-head .thumbnail {
    width: 226px;
    height: 226px;
}
.file-item {
    float: left;
    position: relative;
    padding: 4px;
}
.thumbnail, .img-thumbnail {
    -webkit-box-shadow: 0 1px 2px rgba(0,0,0,0.075);
    box-shadow: 0 1px 2px rgba(0,0,0,0.075);
}
.thumbnail {
    display: block;
    padding: 4px;
    line-height: 1.428571429;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    -webkit-transition: all .2s ease-in-out;
    transition: all .2s ease-in-out;
	margin-bottom:10px;
}
#uploader-head .thumbnail img {
    width: 216px;
	height:216px;
}
.thumbnail>img, .thumbnail a>img {
    display: block;
    height: auto;
    max-width: 100%;
    margin-right: auto;
    margin-left: auto;
}
img {
    vertical-align: middle;
}
img {
    border: 0;
}
.file-item .info {
    position: absolute;
    left: 4px;
    bottom: 4px;
    right: 4px;
    height: 20px;
    line-height: 20px;
    text-indent: 5px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 12px;
    z-index: 10;
}
.file-item .error {
    position: absolute;
    top: 4px;
    left: 4px;
    right: 4px;
    background: red;
    color: white;
    text-align: center;
    height: 20px;
    font-size: 14px;
    line-height: 23px;
}
.webuploader-pick {
    position: relative;
    display: inline-block;
    cursor: pointer;
    background: #00b7ee;
    padding: 10px 15px;
    color: #fff;
    text-align: center;
    border-radius: 3px;
    overflow: hidden;
	display: inline-block;
    margin-bottom: 0;
    padding: 0.5em 1em;
    vertical-align: middle;
    font-size: 1.6rem;
    font-weight: normal;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
    background-image: none;
    border: 1px solid transparent;
    border-radius: 0;
    cursor: pointer;
    outline: 0;
    -webkit-appearance: none;
    -webkit-user-select: none;
}
</style>
<div class="head-css">
  <!--<div class="head-box">
  	<img src="<if condition="empty($userInfo['userPhoto'])">__PUBLIC__/images/default.jpg<else />/{$userInfo['userPhoto']}</if>" class="am-fr am-circle" width="180" height="180px">
  </div>-->


 <input type="hidden" name="userPhoto" id="userPhoto" value="">
	<div id="uploader-head" class="uploader-head">
		<div id="fileList" class="uploader-list">
        	<div id="head-img" class="file-item thumbnail"><img src="<if condition="empty($userInfo['userPhoto'])">__PUBLIC__/images/default.jpg<else />/{$userInfo['userPhoto']}</if>"></div>
        </div>
		<div id="filePicker" class="am-fl">选择图片</div><button type="submit" onClick="upHead()" class="am-btn am-btn-danger am-fr">上&nbsp;&nbsp;传</button>
	</div>
    <div style="clear:both;"></div>

</div>
<script src="__ROOT__/Apps/Wap/View/default/assets/js/jquery.min.js"></script> 
<script src="__ROOT__/Apps/Wap/View/default/assets/js/amazeui.min.js"></script>
<script src="__PUBLIC__/js/common.js"></script>
<script type="text/javascript" src="__PUBLIC__/plugins/webuploader-0.1.5/webuploader.js"></script>
<script type="text/javascript">
$("#userPhoto").val('asdfasdfdsf')
var BASE_URL = "{:C('WEB_URL')}__PUBLIC__/plugins/webuploader-0.1.5/"
jQuery(function() {
    var $ = jQuery,
        $list = $('#fileList'),
        // 优化retina, 在retina下这个值是2
        ratio = window.devicePixelRatio || 1,

        // 缩略图大小
        thumbnailWidth = 300 * ratio,
        thumbnailHeight = 300 * ratio,

        // Web Uploader实例
        uploader;

    // 初始化Web Uploader
    uploader = WebUploader.create({

        // 自动上传。
        auto: true,

        // swf文件路径
        swf: BASE_URL + '/js/Uploader.swf',

        // 文件接收服务端。
        server : '{:U("Wap/Users/upHeadPic")}',

        // 选择文件的按钮。可选。
        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
        pick: '#filePicker',

        // 只允许选择文件，可选。
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/*'
        },
    });

    // 当有文件添加进来的时候
    uploader.on( 'fileQueued', function( file ) {
        var $li = $(
                '<div id="' + file.id + '" class="file-item thumbnail">' +
                    '<img>' +
                '</div>'
                ),
            $img = $li.find('img');
		
        $list.html( $li );

        // 创建缩略图
        uploader.makeThumb( file, function( error, src ) {
            if ( error ) {
                $img.replaceWith('<span>不能预览</span>');
                return;
            }

            $img.attr( 'src', src );
        }, thumbnailWidth, thumbnailHeight );
    });
	// 文件上传过程中创建进度条实时显示。
    uploader.on( 'uploadProgress', function( file, percentage ) {
        var $li = $( '#'+file.id ),
            $percent = $li.find('.progress span');

        // 避免重复创建
        if ( !$percent.length ) {
            $percent = $('<p class="progress"><span></span></p>')
                    .appendTo( $li )
                    .find('span');
        }

        $percent.css( 'width', percentage * 100 + '%' );
    });

    // 文件上传成功，给item添加成功class, 用样式标记上传成功。
    uploader.on( 'uploadSuccess', function( file ) {
        $( '#'+file.id ).addClass('upload-state-done');
    });

    // 文件上传失败，现实上传出错。
    uploader.on( 'uploadError', function( file ) {
        var $li = $( '#'+file.id ),
            $error = $li.find('div.error');

        // 避免重复创建
        if ( !$error.length ) {
            $error = $('<div class="error"></div>').appendTo( $li );
        }

        $error.text('上传失败');
    });

    // 完成上传完了，成功或者失败，先删除进度条。
    uploader.on( 'uploadComplete', function( file ) {
        $( '#'+file.id ).find('.progress').remove();
    });
	uploader.on('uploadAccept', function(file, response) {
		if (response.code == 1) {
			$("#userPhoto").val(response.path)
		}
	});
});

function upHead() {
	var params = {};
	params.userPhoto = $('#userPhoto').val();
	
	$.post("{:U('Wap/Users/upHead')}",params,function(data,textStatus){
	   var json = MXC.toJson(data);
		if(json.code=='1'){
			alert(json.info);
			location.href= "{:U('Wap/Users/profile')}";
		}else{
			$("#errmsg").html("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + json.info);
		}
   });
}
</script>
</body>
</html>
